home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT6 / USERHAND.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-05-10  |  2.0 KB  |  51 lines

  1. ;
  2. ;       Program UserHand ( Chapter 6 )
  3. ;
  4.     page    55,132
  5. CODE    SEGMENT PARA
  6.     ASSUME  CS:CODE
  7. ToOld:                  ;=== Passing control to the old handler
  8.     db      0EAh    ; This is code for JMP FAR
  9. OldOff  dw      0       ; Here will be ofsset
  10. OldSeg  dw      0       ; Here will be segment
  11.  
  12. Handler label   byte            ; Start of new handler for INT 21
  13.     cmp     ah,30h          ; Check function number
  14.     jne     ToOld           ; If not a function 30h - to old handler
  15.     mov     ax,0107h        ; Function 30h - Return the version number
  16.     iret                    ; Return from handler
  17.  
  18. INSTALL:                        ; Installation starts here
  19.     mov     ax,3521h        ; Get handler's address
  20.     int     21h             ;    ES - segment, BX - offset
  21.     cmp     bx,offset Handler ; Vector points to this handler ?
  22.     je      already         ; If so - put message end exit
  23.     mov     cs:OldOff,bx    ; Save offsett of old handler
  24.     mov     cs:OldSeg,es    ; Save segment of old handler
  25.     mov     ax,cs           ; Command segment of this program
  26.     mov     ds,ax           ;    into DX (for setting handler)
  27.  
  28.     mov     dx,offset Handler      ; Address of handler
  29.     mov     ax,2521h        ; Function 25h - Set new handler
  30.     int     21h             ; Dos service call
  31.  
  32.     lea     dx,INSTALL
  33.     add     dx,15
  34.     mov     cx,4            ; Set counter for shift
  35.     shr     dx,cl           ; 4 bits to the right - divide by 16
  36.     add     dx,16           ; Add size of PSP in paragraphs
  37.     mov     ax,3100h        ; Terminate and
  38.     int     21h             ;     state resident
  39.  
  40. already:
  41.     push    cs              ; Copy the value of CS
  42.     pop     ds              ;     into the register DS
  43.     lea     dx,loaded       ; DX := addres of message text
  44.     mov     ax,0900h        ; Function 09 - output string
  45.     int     21h             ; DOS service call
  46.     mov     ax,4C01h        ; Function 4Ch - stop (return code 01)
  47.     int     21h             ; DOS service call
  48. loaded  db      'User handler is already loaded!',10,13,'$'
  49. CODE    ENDS
  50. END     INSTALL
  51.